#!/usr/bin/env python3
# coding:utf-8
import subprocess

p = subprocess.Popen(['ping www.baidu.com -c 2'], shell=True,
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT)

buf = p.stdout.read()
print("执行过程输出: ",buf.decode('utf-8'))
print("执行结果: ",p.returncode)